﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Connect
{
    /// <summary>
    /// Tìm kiếm các địa chỉ IP trên mạng nội bộ
    /// </summary>
    public partial class IPConfig : Form
    {
        #region Mở form
         const int AW_SLIDE = 0X40000;
        const int AW_HOR_POSITIVE = 0X1;
        const int AW_HOR_NEGATIVE = 0X2;
        const int AW_BLEND = 0X80000;

        [DllImport("user32")]
        static extern bool AnimateWindow(IntPtr hwnd, int time, int flags);
        string MainForm;
        public IPConfig(string MainForm)
        {
            InitializeComponent();
            this.MainForm = MainForm;
        }
        protected override void OnLoad(EventArgs e)
        {
            //Load the Form At Position of Main Form
            int WidthOfMain = Application.OpenForms[MainForm].Width;
            int HeightofMain = Application.OpenForms[MainForm].Height;
            int LocationMainX = Application.OpenForms[MainForm].Location.X;
            int locationMainy = Application.OpenForms[MainForm].Location.Y;

            //Set the Location
            this.Location = new Point(LocationMainX + WidthOfMain, locationMainy + 10);

            //Animate form
            AnimateWindow(this.Handle, 500, AW_SLIDE | AW_HOR_POSITIVE);
        }
        #endregion

        #region Di chuyển
  private bool drragging;
        private Point pointclicked;
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                drragging = true;
                pointclicked = new Point(e.X, e.Y);
            }
            else
            {
                drragging = false;
            }
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            drragging = false;
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
         if (drragging)
            {
                Point pointmoveto = default(Point);
                pointmoveto = this.PointToScreen(new Point(e.X, e.Y));
                pointmoveto.Offset(-pointclicked.X, -pointclicked.Y);
                this.Location = pointmoveto;
            }
        }        
        #endregion
       
        private void close_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void search_Click(object sender, EventArgs e)
        {
            try
            {
                dgvdanhsach.DataSource = Network.DanhSachMay(cbworkgroup.Text.Trim(),false);
                tblthongbao.Text = "Danh sách các máy trong mạng LAN";
            }
            catch (Exception ex)
            {
                tblthongbao.Text = ex.Message;
            }
           
        }

        private void setIP_Click(object sender, EventArgs e)
        {
            Connect.ChangeIP f = new Connect.ChangeIP();
            f.ShowDialog();

        }

        private void tblthongbao_Click(object sender, EventArgs e)
        {
            Close();
        }


    
      
    }
}
